package com.qiantu.phone.ui.activity;

import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hjq.base.BaseAdapter;
import com.qiantu.api.db.LLDeviceDBManager;
import com.qiantu.api.entity.DeviceBaseConfigInfo;
import com.qiantu.api.entity.DeviceBean;
import com.qiantu.api.entity.DeviceTriggerType;
import com.qiantu.api.utils.DeviceInfoParseUtil;
import com.qiantu.phone.R;
import com.qiantu.phone.app.AppActivity;
import com.qiantu.phone.ui.adapter.DeviceStatusAdapter;
import com.qiantu.phone.ui.uiutil.LLDeviceUtil;

/**
 * time   : 2021/12/22
 */
public final class SelectDeviceStatusActivity extends AppActivity {

    private RecyclerView recyclerView;
    private DeviceStatusAdapter mDeviceStatusAdapter;
    private String deviceSerialNo;
    private DeviceBean mDevice;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_select_device_status;
    }

    @Override
    protected void initView() {
        deviceSerialNo = getString("device_serial_no");
        mDevice = LLDeviceDBManager.getInstance(this).get(deviceSerialNo);
        if(mDevice.getName()!=null){
            setTitle(mDevice.getName());
        }
        recyclerView = findViewById(R.id.recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        mDeviceStatusAdapter = new DeviceStatusAdapter(getContext());
        recyclerView.setAdapter(mDeviceStatusAdapter);
        DeviceBaseConfigInfo deviceBaseConfigInfo = DeviceInfoParseUtil.parseData(getContext(), mDevice.getDeviceType(), DeviceBaseConfigInfo.class);
        mDeviceStatusAdapter.setData(deviceBaseConfigInfo.getTriggerData());
        mDeviceStatusAdapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(RecyclerView recyclerView, View itemView, int position) {
                DeviceTriggerType deviceTriggerType = mDeviceStatusAdapter.getData().get(position);
                String conditionSerialNo = getString("serial_no");
                Boolean isNew = getBoolean("isNewVersion");
                if(isNew){
                    LLDeviceUtil.startDeviceStatusActivityNew(getContext(), deviceTriggerType.getKey(), mDevice,null,0);
                }else{
                    LLDeviceUtil.startDeviceStatusActivity(getContext(), deviceTriggerType.getKey(), mDevice, conditionSerialNo);
                }
            }
        });
    }

    @Override
    protected void initData() {

    }
}